package com.student.service.impl;

import com.student.dto.ResponseDto;
import com.student.mapper.SnackCardMapper;
import com.student.pojo.SnackCard;
import com.student.service.SnackCardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @BelongsProject: makeups
 * @BelongsPackage: com.student.service.impl
 * @Author: 小徐
 * @CreateTime: 2024-12-22 23:44
 * @Description: TODO
 * @Version: 1.0
 */
@Service
public class SnackCardServiceImpl implements SnackCardService {
    @Autowired
    private SnackCardMapper snackCardMapper;

    @Override
    public ResponseDto addCard(Integer userId, Integer goodId, Integer num) {
        List<SnackCard> snackCard=snackCardMapper.select(goodId);
        if (snackCard.size()>0) {
            Integer res = snackCardMapper.updateNum(userId, goodId, num);
            if (res >= 1) {
                return ResponseDto.success(null);
            }
        }
        Integer res = snackCardMapper.addCard(userId, goodId, num);
        if (res >= 1) {
            return ResponseDto.success(null);
        }
        return ResponseDto.error(null);
    }

    @Override
    public ResponseDto getAllCard(Integer userId) {
        List<SnackCard> snackCards = snackCardMapper.getAllCard(userId);
        if (snackCards.size() > 0) {
            return ResponseDto.success(snackCards);
        }
        return ResponseDto.error(null);
    }

    @Override
    public ResponseDto addNumber(Integer id, Integer number) {
        Integer res = snackCardMapper.updateNumber(id,number);
        if (res >= 1) {
            return ResponseDto.success(null);
        }
        return ResponseDto.error(null);
    }


}